package com.welab.springcloud.demo.common.domain;


import lombok.Data;

@Data
public class ResponseResult<T> {

	public static final int SUCCESS_CODE = 0;
	public static final int FAIL_CODE = -1;

	private int status;
	private T data;
	private String message;

	ResponseResult(T data) {
		status = SUCCESS_CODE;
		message = "ok";
		data = data;
	}

	public ResponseResult(int status, T data, String msg) {
		this.status = status;
		this.data = data;
		this.message = msg;
	}

	public ResponseResult result(int status, T data, String msg) {
		return new ResponseResult(status, data, msg);
	}

	public static <E> ResponseResult<E> success(E data) {
		return new ResponseResult<>(SUCCESS_CODE, data, "success");
	}

	public static <E> ResponseResult<E> fail() {
		return new ResponseResult<>(FAIL_CODE, null, "fail");
	}

	public static <E> ResponseResult<E> fail(Integer code, String msg) {
		return new ResponseResult<>(code, null, msg);
	}

}
